<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>核销确认</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <style type="text/css">
        .searchArea .fieldBox .label{width: 60px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
    </style>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox ">
                    <div class="label">批次号</div>
                    <div class="field">
                        <input name="batNo" id="batNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox ">
                    <div class="label">实收总金额</div>
                    <div class="field">
                        <input name="repayAmt" id="repayAmt" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                
	             <div class="fieldBox ">
	                <div class="label">创建时间</div>
	                <div class="field">
	                	<input name="crtTmStart" id="crtTmStart" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                	至：
	                	<input name="crtTmEnd" id="crtTmEnd" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                </div>
	            </div>
	            
	            <div class="fieldBox ">
	                <div class="label">提交时间</div>
	                <div class="field">
	                	<input name="commitTmStart" id="commitTmStart" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                	至：
	                	<input name="commitTmEnd" id="commitTmEnd" type="text" class="ui-datepicker" value="" ligerui="width: 115">
	                </div>
	            </div>
                
                <div class="fieldBox ">
					<div class="label">状态</div>
					<div class="field">
						<select name="commitType" id="commitType" ligerui="width: 160">
						 	<option value=" " seleted>请选择</option>
							<option value="-1">提交失败</option>
							<option value="0">待确认提交</option>
							<option value="1">提交成功</option>
						</select>
					</div>
				</div>
                
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round" >批量确认提交</span>
                    <span id="expBtn" class="sq-button sq-button-round" onclick="exportexcel();">下载明细</span>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/mcr/mcrWriteOffConfirmSummary/initList.do',
            method: 'get',
            columns: [
            	{ display: '批次号', name: 'batNo', width: 120, enabledSort:true },
	            { display: '还款笔数', name: 'repayNum', width: 150, enabledSort:true},
	            { display: '实收总金额(元)', name: 'repayAmt', width: 150, enabledSort:true},
	            { display: '实收本金(元)', name: 'repayPrincipal', width: 150, enabledSort:true},
	            { display: '实收利息(元)', name: 'repayInterest', width: 150, enabledSort:true},
	            { display: '实收罚息(元)', name: 'repayPenaltyInterest', width: 150, enabledSort:true},
	            { display: '创建时间',  name: 'crtTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate },
	            { display: '提交时间',  name: 'commitTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
	            { display: '状态', name: 'commitType', width: 150, enabledSort:true,
                    render:function(rowData){
                        if(rowData.commitType=="-1"){
                           /*  return "提交失败"; */
                        	var i='<a class="sq-button-hasicon" href="javascript:failReason(';
    	                    i+="'"+rowData.failReason+"'";
    	                    i+=')"><i class="sqBtnIco_4"></i>提交失败</a>';
                       		return i;
                        }else if(rowData.commitType=="0"){
                            return "待确认提交";
                        }else{
                        	return "提交成功";
                        }
                    }
                },
	            
	            getGridOperColumnContent()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

        
      //批量确认提交
    	$("#addBtn").click(function(event) {
    	  
    		var selectedRows = grid.getSelectedRows();
    		if(selectedRows.length == 0){
    			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warring"});
    			return;
    		}
    		top.$.ligerDialog.confirm("确认提交选中项吗?", function (flag) {
    			if(!flag){
    				return;
    			}else{
    				var batNos = [];
    				var repayAccountMoney =0;
    				var repayAccountNum = 0;
    				for (var i = 0; i < selectedRows.length; i++) {
    					if (selectedRows[i].commitType == 1 ) {
    	                     $.ligerDialog.SQalert({content: "选中数据中有比推送成功数据，请重新选择", SQ_type: "warning"});
    	                     return;
    	                 }
    					batNos.push(selectedRows[i].batNo);
    					repayAccountMoney = Number(repayAccountMoney) + Number(selectedRows[i].repayAmt);
    					repayAccountNum = Number(repayAccountNum) + Number(selectedRows[i].repayNum);
    				}
    				if(batNos.length==0)return;
    				$.ligerDialog.open({
    		            width: 800,
    		            height: 500,
    		            title: '核销确认提交',
    		            url: '<%=path%>/mcr/mcrWriteOffConfirmSummary/confirmAndSubmitView.do?batNos='+batNos+'&repayAccountMoney='+repayAccountMoney+'&repayAccountNum='+repayAccountNum
    		        });
    			}
    		});
        
    });
    });
  //Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 280,
                render: function (rowdata, rowindex, value){
                    var h='<a class="sq-button-hasicon" href="javascript:confirmAndSubmitView(';
                        h+="'"+rowdata.batNo+"',";
                        h+="'"+rowdata.repayAmt+"',";
	                    h+="'"+rowdata.repayNum+"'";
                        h+=')"><i class="sqBtnIco_4"></i>确认并提交</a>';
                   
                   	var i='<a class="sq-button-hasicon" href="javascript:checkDetails(';
	                    i+="'"+rowdata.batNo+"'";
	                    i+=')"><i class="sqBtnIco_4"></i>查看明细</a>';
                   	var returnStr = h;  
                   	if(rowdata.commitType == 0){
                       	returnStr = h + i;
                    }else{
                    	returnStr = i;
                    }
                   	return returnStr;
                }
            }
    	return data;
	}
  
  	//确认并提交
    function confirmAndSubmitView(batNo,repayAmt,repayNum){
        $.ligerDialog.open({
            width: 800,
            height: 500,
            title: '提交',
            url: '<%=path%>/mcr/mcrWriteOffConfirmSummary/confirmAndSubmitView.do?batNos='+batNo+'&repayAccountMoney='+repayAmt+'&repayAccountNum='+repayNum
        });
    }
  	
  	//查看明细
    function checkDetails(batNo) {
	   	 $.ligerDialog.open({
	            width: 1200,
	            height: 500,
	            title: '明细',
	            url: '<%=path%>/mcr/mcrWriteOffConfirmDetail/checkDetails.do?batNo='+batNo
	        });
	}
  
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
    
    function failReason(failReason) {
    	$.ligerDialog.SQalert({content: failReason, SQ_type: "warring"});
	}
    
    
    //批量导出excel
    function exportexcel(){
    	var batNos = [];
    	var rows = grid.getSelecteds();
    	for (var i = 0; i < rows.length; i++) {
    		batNos.push(rows[i].batNo);
        }
    	if(batNos.length < 1){
    		 $.ligerDialog.SQalert({content: "请至少选中一条数据导出", SQ_type: "warning"});
    		 return;
    	}
    	var params = "batNos="+batNos;
    	window.location.href = '<%=path%>/mcr/mcrWriteOffConfirmDetail/exportexcel.do?' + params;
	}
</script>

</body>
</html>
